package com.amit;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestServlet extends HttpServlet{
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		//1 collect the request parameters
		String nm=request.getParameter("name");
		String em=request.getParameter("email");
		
		String msg="Hi"+nm+"! your Email is"+em;
		System.out.println("In test servlet");
		
		System.out.println(nm);
		System.out.println(em);
		System.out.println(msg);
		
		request.setAttribute("MSG", msg);
		PrintWriter out=response.getWriter();
		out.println("<h1>Before forward: I am from testServlet</h1>");
		System.out.println("Before forward: I am from testServlet");
		
		//out.flush();
		//out.close();
		
		RequestDispatcher rd=request.getRequestDispatcher("hello.jlc");
		rd.forward(request, response);
		
		out.println("<h1>After forward: I am from testServlet</h1>");
		
		
		out.flush();
		out.close();
		System.out.println("After forward: I am from testServlet");
	
	}

}
